﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class UIHR : ViewBase
    {
        public VHRSTAMM TMV
        {
            get
            {
                return (VHRSTAMM)MV;
            }
        }
        #region ==BENID===========
        public static readonly DependencyProperty BENIDProperty = DependencyProperty.Register("BENID",
            typeof(string), typeof(UIHR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBENIDChanged));
        public string BENID
        {
            get
            {
                return (string)GetValue(BENIDProperty);
            }
            set
            {
                SetValue(BENIDProperty, value);
            }
        }
        private static void OnBENIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIHR;
            if (src != null)
            {
                src.BENID = (string)e.NewValue;
            }
        }
        #endregion

        #region ==STRASSE===========
        public static readonly DependencyProperty STRASSEProperty = DependencyProperty.Register("STRASSE",
            typeof(string), typeof(UIHR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSTRASSEChanged));
        public string STRASSE
        {
            get
            {
                return (string)GetValue(STRASSEProperty);
            }
            set
            {
                SetValue(STRASSEProperty, value);
                OnSTRASSEChg();
            }
        }
        private static void OnSTRASSEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIHR;
            if (src != null)
            {
                src.STRASSE = (string)e.NewValue;
            }
        }
        public virtual void OnSTRASSEChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.HRSTRASSE = STRASSE.Trim().PadRight(40);
        }
        #endregion

        #region ==dwHR===========
        public static readonly DependencyProperty dwHRProperty = DependencyProperty.Register("dwHR",
            typeof(DataRow), typeof(UIHR),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwHRChanged));
        public DataRow dwHR
        {
            get
            {
                return (DataRow)GetValue(dwHRProperty);
            }
            set
            {
                SetValue(dwHRProperty, value);
            }
        }
        private static void OdwHRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIHR;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwHR = row;
            }
        }
        #endregion

        public UIHR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
           
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwHR = dwMaster;
            if (dwMaster == null)
            {
                BENID = "".PadRight(8);
            }
            else
            {
                BENID = dwMaster["HRBENID"].ToString();
            }
        }
        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
        }

    }
}
